<?php

namespace App\Http\Controllers\Web;

use App\Models\Users;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class RegisterController extends Controller
{

    /**
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     * @name 注册页面
     */
    public function index(){
        return view('web.register.index');
    }

    /**
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     * @name 注册行为
     */
    public function register(){
        $this->validate(request(),[
            'name'=>'required|min:3|unique:users,name',
            'email'=> 'required|unique:users,email|email',
            'password'=>'required|min:5|confirmed'
        ]);
        $name=request('name');
        $email=request('email');
        $password=bcrypt(request('password'));
        Users::create(compact('name','email','password'));
        return redirect('/login');
    }
}
